package com.homedo.odin.solution.controller.pc;

import com.homedo.core.common.base.controller.BaseController;
import com.homedo.core.common.base.dto.ResultData;
import com.homedo.odin.solution.contract.pc.AddSolDownloadReq;
import com.homedo.odin.solution.contract.pc.DlAndCollectSolutionResp;
import com.homedo.odin.solution.contract.wap.SolutionDownloadsResp;
import com.homedo.odin.solution.service.bizservice.pc.DownloadsBizService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: zhaoxudong
 * @date: 2018/4/8 15:24
 * @Description:
 */
@Api(description = "下载接口", tags = {"Downloads"}, produces = MediaType.APPLICATION_JSON_VALUE)
@RestController
@RequestMapping("/downloads")
public class DownloadsController extends BaseController<DownloadsBizService> {

    @ApiOperation(value = "PC_获取方案下载最新动态", notes = "PC_获取方案下载最新动态", response = SolutionDownloadsResp.class)
    @GetMapping("/solutions")
    public ResultData solutions(@ApiParam("当前页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam("每页数量") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        SolutionDownloadsResp resp = baseService.solutions(pageNum, pageSize);
        return ResultData.newInstance(resp);
    }

    @ApiOperation(value = "PC_新增方案下载记录", notes = "PC_新增方案下载记录")
    @PostMapping("/solutions")
    public ResultData addSolutions(@RequestBody AddSolDownloadReq req) {
        baseService.addSolutions(req);
        return ResultData.newInstance();
    }

    @ApiOperation(value = "PC_获取用户下载方案列表", notes = "PC_获取用户下载方案列表", response = DlAndCollectSolutionResp.class)
    @GetMapping("/{userId}/solutions")
    public ResultData userDownloadSol(@ApiParam(value = "用户id", required = true) @PathVariable("userId") Integer userId,
            @ApiParam(value = "方案名称") @RequestParam(value = "solutionName", required = false) String solutionName,
            @ApiParam(value = "方案状态") @RequestParam(value = "solutionStatus", required = false) Integer solutionStatus,
            @ApiParam(value = "创建时间(开始)") @RequestParam(value = "startDate", required = false) Long startDate,
            @ApiParam(value = "创建时间(结束)") @RequestParam(value = "endDate", required = false) Long endDate,
            @ApiParam(value = "当前页码", required = true) @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页记录数", required = true) @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        DlAndCollectSolutionResp resp = baseService
                .userDownloadSol(userId, solutionName, solutionStatus, startDate, endDate, pageNum, pageSize);
        return ResultData.newInstance(resp);
    }
}
